<?php

include_once($cfgPaths['lib'].'cms/type/cmsEditType.o.inc.php');

function __xics_meta_type_cmp ($a, $b)
{
    if ($a['path'] == $b['path'])
        return 0;
    return ($a['path'] < $b['path']) ? -1 : 1;
}

class cmsEditXICSMetaType extends cmsEditType {

 function registerFields () {
   $this->map = array();
 }

 function render_html () {
  global $dba, $objtree, $env;
  $tree = $objtree->getTable();
  $meta = $dba->getElementMeta($this->getValue('element_id'));
  $cats = $dba->getElementCats($this->getValue('element_id'));
  
  
  $html .= '<div class="xicstypeplugin">';
  $html .= '<a href="javascript:void(0);" onclick="$(\'#objectmetadata\').toggle(\'fast\');$(this).hide()"><h3>'.$this->descr.': Anzeigen ...</h3></a>'.$this->showFields()."\n";
  $html .= '  <div style="display:none" id="objectmetadata" border="0">'."\n";
  if (xicsEdition(PRO_EDITION))
  {
    $html .= '      <h3>Meta-Name des Content Objektes:</h3>'."\n";
    $html .= '          <input type="text" style="width:450px" tabindex="'.$this->sender->getNextTabindex($this->name.'name').'" maxlength="255" name="'.$this->name.'name" value="'.htmlspecialchars($meta['meta_name']).'" />'."\n";
    $html .= '      <h3>Meta-Beschreibung des Content Objektes:</h3>'."\n";
    $html .= '              <textarea style="width:450px" tabindex="'.$this->sender->getNextTabindex($this->name.'description').'" name="'.$this->name.'description" cols="50" rows="10" onfocus="'.$fu.'" onclick="'.$fu.'" onchange="'.$fu.'" onKeydown="'.$fu.'"'."\n";
    $html .= '               onKeyup="'.$fu.'">'.htmlspecialchars($meta['meta_description']).'</textarea><br>'."\n";
    $html .= '               Zeichen:<input name="'.$this->name.'_anzahl" value="'.strlen($this->getValue($this->name.'description')).'" size="5"> (max 65535)'."\n";
  }
  $html .= '      <h3>Objekte-Kategorien:</h3>'."\n";
  $html .= "\n".'<select multiple="multiple" size="10" style="width:450px" tabindex="'.$this->sender->getNextTabindex('category_id').'" name="category_id[]">';
  for ($i = 0; $i < count($tree); $i++)
  {
    $tree[$i]['path'] = $objtree->extractPathStr($tree[$i]['id'],'name',' -> ',true); 
    
  }
  usort($tree, "__xics_meta_type_cmp");
  foreach ($tree As $node)
  {
    if ($node['allowed_type'] != $GLOBALS['env']->param('type')) continue;
	$html .= '<option value="'.$node['id'].'"';
	if (is_array($cats) && in_array($node['id'],$cats)) $html .= ' selected="selected"';
	$html .= '>'.$node['path'].'</option>'."\n";
  }
  $html .= '               </select><br/>Mehrfachauswahl mit Strg bzw. Command'."\n";
  $html .= '      </div>'."\n";
  $html .= '</div><!-- / type meta -->'."\n";
  return $html;
 }

 function render_javascript () {
 }

}


?>
